package com.alibaba.controller;


import com.alibaba.bean.*;
import com.alibaba.service.DataService;
import com.alibaba.service.FollowNumService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("follow")
public class FollowNumController {
    @Autowired
    FollowNumService followNumService;
    @Autowired
    DataService dataService;

    @RequestMapping(value = "followNum", method = RequestMethod.POST)
    @ResponseBody
    public FollowNum follownum(@RequestParam("userId") int userId) {
        FollowNum followNum = new FollowNum();

        Data data1 = new Data();
        data1.setUserName(dataService.getUser(userId).getUsername());
        data1.setAvatar(dataService.getUser(userId).getAvatar());
        data1.setUserId(dataService.getUser(userId).getId());
        data1.setFansNum(dataService.fansnum(userId));
        data1.setFollowNum(dataService.followsnum(userId));
        followNum.setResult(true);
        followNum.setErrorMsg("查询成功");
        followNum.setData(data1);

        return followNum;
    }

    @RequestMapping("notice")
    @ResponseBody
    public NoticeResult find() {
        NoticeResult noticeResult=new NoticeResult();
        List<Notice> noticeList= followNumService.findAll();
        noticeResult.setData(noticeList);
        noticeResult.setResult(true);
        noticeResult.setErrorMsg("成功");
        return noticeResult;
    }
}




